// -*- c++ -*-
/**
  @file SS_LambertianComponent.pix
  @author Morgan McGuire morgan@cs.williams.edu

  For use with G3D::SuperShader.
  This file is included into NonShadowedPass.pix and 
  ShadowMappedLightPass.pix.

  Lambertian is included in a different location in the shadow mapped
  pass in order to allow alpha testing early.

  @created 2007-12-18
  @edited  2010-09-07
 */
#   ifndef invPi
#       define invPi (0.318309886)
#   endif

    const vec3 BLACK = vec3(0.0, 0.0, 0.0);

    vec3 wsEyePos = g3d_CameraToWorldMatrix[3].xyz;

#   if defined(NORMALBUMPMAP)
        vec3 wsN;
        vec2 offsetTexCoord;
        applyBumpMap(wsN, offsetTexCoord);
#   else
        // World space normal
        vec3 wsN = tan_Z.xyz * backside;
        vec2 offsetTexCoord = texCoord;
#   endif
    wsN = normalize(wsN);

#   if (defined(LAMBERTIANCONSTANT) || defined(LAMBERTIANMAP))
        vec4 lambertianColor =
#       ifdef LAMBERTIANCONSTANT
            lambertianConstant
#           ifdef LAMBERTIANMAP
                * texture2D(lambertianMap, offsetTexCoord)
#           endif
#       else
            texture2D(lambertianMap, offsetTexCoord)
#       endif
        ;
	  lambertianColor.rgb *= invPi;
#   endif
/* End SS_LambertianComponent.pix */
